<template>
	<view class="main-page">
		<view class="column-container width-100p" v-if="dataList.length > 0">
			<view class="data-item" v-for="(item , index) in dataList" :key="index"
			@click="gotoDetail(item)">
				<view class="row-container">
					<image class="wh-34" src="../../static/ic_notice_grey.png" v-if="item.checkView == 1"></image>
					<image class="wh-34" src="../../static/ic_notice_list.png" v-else></image>
					
					<text class="font-999-32 ml-15" style="line-height: 44rpx;"
					 v-if="item.checkView == 1">
						{{item.title}}</text>
					<text class="font-333-32 font-weight-600 ml-15" 
					style="line-height: 44rpx;" v-else>
						{{item.title}}</text>	
				</view>
				<text class="font-999-24 mt-14">{{item.createTime}}</text>
			</view>
		</view>
		
		<view class="column-container-center width-100p mt-272" v-else>
			<image src="../../static/ic_empty.png" class="wh-70 mb-30"></image>
			<text class="font-333-36 font-weight-600" >暂无数据</text>
		</view>
		
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				dataList:[],
				page:1,
				hasMoreData:false
			}
		},
		
		onShow() {
			this.page = 1
			this.loadData()
		},
		
		onPullDownRefresh() {
			this.page = 1
			this.loadData()
		},
		
		onReachBottom() {
			if (this.hasMoreData){
				this.page ++
				this.loadData()
			}
		},
		
		methods: {
			gotoDetail(item){
				uni.navigateTo({
					url:'./noticeDetail?noticeId=' + item.id
				})
			},
			
			loadData(){
				let that = this
				this.http({
					url:'/notice/findNoticeList',
					method:'POST',
					data:{
						pageNo : that.page,
						pageSize : 20,
						tagType : this.config.noticeTagType
					},
					success(res){
						if (res.code == 200){
							if (that.page == 1){
								that.dataList = res.data
							} else{
								that.dataList = [...that.dataList, ...res.data]
							}
							that.hasMoreData = res.data.length >= 20
						}
						uni.stopPullDownRefresh()
					},
					failed(e){
						uni.stopPullDownRefresh()
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.data-item{
		display: flex;
		flex-direction: column;
		width: calc(100% - 108rpx);
		background: white;
		border-radius: 16rpx;
		margin: 20rpx 30rpx 0rpx 30rpx;
		padding: 24rpx;
	}
</style>
